#include "cadcall.h"

static QStringList LIST_CALL = (QStringList()  << "拨打" << "呼叫" << "拨号" );

CADCall::CADCall(QObject *parent):CAudioControlDevice(parent)
{

}

void CADCall::addDevice(DEVICE_OPERATION *d)
{
    _device_list.append(d);
}

void CADCall::clearDevice()
{
    foreach (DEVICE_OPERATION *d, _device_list) {
        d->deleteLater();
    }

    _device_list.clear();
}

DEVICE_OPERATION * CADCall:: parseWord(QString word)
{
    QString op,name,value;

    foreach (QString s, LIST_CALL) {
        if(word.contains(s))
        {
            op = DEVICE_ACTION_CALL;
            name = s;
            int begin = word.indexOf(s);
            if(begin>=0){
                int start = begin + name.length();
                value = word.mid(start,word.length()-start);
            }
            break;
        }
    }


    if(name.isEmpty() || op.isEmpty() || value.isEmpty())
    {
        return nullptr;
    }

    qDebug()<< "Audio: found device " << name;
    DEVICE_OPERATION *device_op = new DEVICE_OPERATION();
    device_op->_audio_name = name;
    device_op->_audio_operation = op;
    device_op->_audio_value = value;

    return device_op;
}


bool CADCall::actionAudionControl(DEVICE_OPERATION *devOp)
{
    return false;
}
